package com.flash.BusinessData.service.impl;

import com.flash.BusinessData.entity.DealData;
import com.flash.BusinessData.mapper.DealDataMapper;
import com.flash.BusinessData.service.DealDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class DealDataServiceImpl implements DealDataService {
    @Autowired
    private DealDataMapper dealDataMapper;

    /**
     * 按条件查询
     * @param dealData
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<DealData> selectDealDataMap(DealData dealData, int page, int limit) {
        HashMap map = new HashMap();
        map.put("strWhere", buildWhere(dealData));
        map.put("page", (page - 1) * limit);
        map.put("limit", limit);
        return dealDataMapper.selectDealDataMap(map);
    }

    /**
     * 分页
     * @return
     */
    @Override
    public int selectCountDealData() {
        return dealDataMapper.selectCountDealData();
    }

    /**
     * 增加
     * @param dealData
     * @return
     */
    @Override
    public int insertDealData(DealData dealData) {
        System.out.println("这是添加Impl");
        return dealDataMapper.insertDealData(dealData);
    }

    /**
     * 删除
     * @param dealId
     * @return
     */
    @Override
    public int deleteDealData(String dealId) {
        return dealDataMapper.deleteDealData(dealId);
    }

    /**
     * 修改
     * @param dealData
     * @return
     */
    @Override
    public int updateDeaData(DealData dealData) {
        return dealDataMapper.updateDeaData(dealData);
    }


    /**
     * 条件查询的方法
     * @param dealData
     * @return
     */
    public String buildWhere(DealData dealData) {
        StringBuffer strWhere = new StringBuffer();
        if (dealData.getSecurityName() != null && !dealData.getSecurityName().equals("")) {
            System.out.println(dealData.getSecurityName() );
            strWhere.append(" and SecurityName like '%" + dealData.getSecurityName()  + "%'");
        } else if (dealData.getDealTime() != null && !dealData.getDealTime().equals("")) {
            System.out.println(dealData.getEndTime());
            strWhere.append(" and dealTime like '%" + dealData.getDealTime() + "%'");
        }
        System.out.println(strWhere+" 8");
        return strWhere.toString();
    }
}
